Component({
  data: {
    active: 0,
    list: [
      {
        pagePath: '/pages/home/index',
        text: '首页',
        icon: 'home',
      },
      {
        pagePath: '/pages/family/index',
        text: '我的家庭',
        icon: 'user',
      },
      {
        pagePath: '/pages/camera/index',
        text: '我的摄像头',
        icon: 'camera',
      },
    ],
  },

  methods: {
    onChange(e) {
      const index = e.detail.value;
      const path = this.data.list[index].pagePath;
      wx.switchTab({
        url: path,
      });
    },

    init() {
      const page = getCurrentPages().pop();
      const route = page ? page.route : '';
      const active = this.data.list.findIndex(
        (item) => item.pagePath === `/${route}`
      );
      this.setData({ active });
    }
  },
}); 